import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;

public class demo05 {
    public static void test01() throws InterruptedException {
        EdgeOptions options = Driver.getDriver();
        WebDriver driver = new EdgeDriver(options);
        driver.get("file:///D:/bitejava/selenium-html/selenium-html/alert.html#");
        driver.findElement(By.cssSelector("#tooltip")).click();
        Thread.sleep(2000);
        Alert alert = driver.switchTo().alert();
//        alert.accept();
        alert.dismiss();
        Thread.sleep(2000);
        driver.quit();
    }

    public static void test02() throws InterruptedException {
        EdgeOptions options = Driver.getDriver();
        WebDriver driver = new EdgeDriver(options);
        driver.navigate().to("file:///D:/bitejava/selenium-html/selenium-html/confirm.html");
        driver.findElement(By.xpath("/html/body/input")).click();
        Thread.sleep(1000);
        Alert alert = driver.switchTo().alert();
        alert.dismiss();
        Thread.sleep(1000);
        driver.navigate().refresh();
        Thread.sleep(1000);
        driver.findElement(By.xpath("/html/body/input")).click();
        Thread.sleep(1000);
        alert = driver.switchTo().alert();
        alert.accept();
        Thread.sleep(1000);
        driver.quit();
    }

    public static void test03() throws InterruptedException {
        EdgeOptions options = Driver.getDriver();
        WebDriver driver = new EdgeDriver(options);
        driver.get("file:///D:/bitejava/selenium-html/selenium-html/Prompt.html");
        driver.findElement(By.cssSelector("body > input[type=button]")).click();
        Thread.sleep(1000);
        Alert alert = driver.switchTo().alert();
        System.out.println(alert.getText());
        Thread.sleep(1000);
        alert.dismiss();
        driver.findElement(By.cssSelector("body > input[type=button]")).click();
        Thread.sleep(1000);
        alert = driver.switchTo().alert();
        alert.sendKeys("hello 加藤惠");
        alert.accept();
        Thread.sleep(2000);
        driver.quit();
    }

    public static void test05() throws InterruptedException {
        EdgeOptions options = Driver.getDriver();
        WebDriver driver = new EdgeDriver(options);
        driver.get("file:///D:/bitejava/selenium-html/selenium-html/upload.html");
        driver.findElement(By.cssSelector("body > div > div > input[type=file]")).sendKeys("D:\\桌面\\aa.txt");
        Thread.sleep(2000);
        driver.quit();
    }

    public static void test06(){
        EdgeOptions options = Driver.getDriver();
//        options.addArguments("-headless");
        WebDriver driver = new EdgeDriver(options);
        driver.get("https://www.baidu.com");
        driver.quit();
    }

    public static void test07(){
        EdgeOptions options = Driver.getDriver();
//        options.addArguments("-headless");
//        options.setPageLoadStrategy(PageLoadStrategy.EAGER);
//        options.setPageLoadStrategy(PageLoadStrategy.NONE);
        options.setPageLoadStrategy(PageLoadStrategy.NORMAL);
        WebDriver driver = new EdgeDriver(options);
        driver.get("https://www.bilibili.com");
        driver.findElement(By.cssSelector("#i_cecream > div.bili-feed4 > div.bili-header.large-header > div.bili-header__channel > div.right-channel-container > div.channel-items__right > a:nth-child(6) > span"));
        driver.quit();
    }

    public static void main(String[] args) throws InterruptedException {
        test07();
    }
}
